<?php
/* 
* @Title:  [栏目模型]
* @Author: {chenlei} [chenleib5@126.com]
* @Date:   2014-04-06 20:24:21
* @Last Modified by:   Administrator
* @Last Modified time: 2014-04-10 16:52:39
* @Copyright:  [hn7m.com]
*/
class ChannelModel extends Model{
	public $table="channel";
	/**
	 * [$validate 自动验证]
	 * @var array
	 */
	public $validate=array(
		array('nname','nonull','栏目名称不能为空',2,3)
		);
	/**
	 * [add_data 添加栏目]
	 */
	public function add_data(){
		$attr=Q('post.nname');
		$preg="/[\s,\r\n]+/is";
		if (!preg_match($preg, $attr)) {
			$this->error='格式不正确,必须以","或者"换行"结束';
			return false;
		}

		$arr=preg_split($preg, $attr);
		//去重
		$arr=array_unique($arr);

		//循环插入
		foreach ($arr as $key => $value) {
			if(empty($value)) continue;
			$data=array('nname'=>$value);
			$this->add($data);
		}
		return true;
	}
	/**
	 * [get_data 获得所有数据]
	 * @return [type] [description]
	 */
	public function get_data(){
		return $this->findAll();
	}
	/**
	 * [del_data 按主键删除数据]
	 * @param  [type] $nid [description]
	 * @return [type]      [description]
	 */
	public function del_data($nid){
		return $this->del($nid);
	}
	/**
	 * [edit_data 按主键更新数据]
	 * @param  [type] $nid [description]
	 * @return [type]      [description]
	 */
	public function edit_data($nid,$data){
		return $this->where(array('nid'=>$nid))->save($data);
	}
}
?>